﻿@model NetPageCommon.PageModelSample;


<nav aria-label="...">
    <ul class="pagination">

        @{
            int page = Model.page;
            int size = Model.size;
            int total = Model.total;
            int count = total / size;
            int yushu = total % size;
            string url = Model.url;
            if (yushu > 0)
            {
                count += 1;
            }

            if (page == 1)
            {
                <li class="page-item disabled" title="已经是第一页">
                    <span class="page-link">首页</span>
                </li>
                <li class="page-item disabled" title="已经是第一页">
                    <span class="page-link">上一页</span>
                </li>
                // <li class="page-item active" aria-current="page">
                //     <span class="page-link">1</span>
                // </li>
            }
            else
            {
                int pagePrev = page - 1;
                <li class="page-item"><a class="page-link" href="@url?page=1&size=@size">首页</a></li>
                <li class="page-item">
                    <a class="page-link" href="@url?page=@pagePrev&size=@size">上一页</a>
                </li>
               
            }


            if (count <= 10 || page <= 5)
            {

                for (int i = 1; i <= (count<=10?count:10); i++)
                {
                    <li class="page-item @(page==i?"active":"")"><a class="page-link" href="@url?page=@i&size=@size">@i</a></li>
                }
            }
            else if ((count - 5) > page)
            {
                int start = page - 4;
                int end = (page + 5) > count ? count : page + 5;
                for (int i = start; i <= end; i++)
                {
                    <li class="page-item @(page==i?"active":"")"><a class="page-link" href="@url?page=@i&size=@size">@i</a></li>
                }
            }
            else
            {
                int start = count - 10;
                int end = count;
                for (int i = start; i <= end; i++)
                {
                    <li class="page-item @(page==i?"active":"")"><a class="page-link" href="@url?page=@i&size=@size">@i</a></li>
                }
            }



            // <li class="page-item"><a class="page-link" href="@url?page=3&size=@size">3</a></li>

            if (page == count)
            {
                <li class="page-item disabled" title="已经是最后一页">
                    <a class="page-link" href="#">下一页</a>
                </li>
                <li class="page-item disabled" title="已经是最后一页">
                    <a class="page-link" href="#">末页</a>
                </li>
            }
            else
            {
                int pageNext = page + 1;
                <li class="page-item">
                    <a class="page-link" href="@url?page=@pageNext&size=@size">下一页</a>
                </li>
                <li class="page-item">
                    <a class="page-link" href="@url?page=@count&size=@size">末页</a>
                </li>
            }

            // <li class="page-item">
            //     <input type="text" placeholder="输入页码"  width="60" />
            // </li>
            // <li class="page-item">
            //     <a class="page-link" href="@url?page=@count&size=@size">跳转</a>
            // </li>
        }
    </ul>
</nav>